<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
    xmlns:rifcs="http://ands.org.au/standards/rif-cs/registryObjects"
    xmlns:vxu="http://www.versi.edu.au/xmlutils/vxu.xsl"
    exclude-result-prefixes="xs xd vxu"
    version="2.0"
    xsi:schemaLocation=
        "http://ands.org.au/standards/rif-cs/registryObjects http://services.ands.org.au/documentation/rifcs/1.2.0/schema/registryObjects.xsd"    
    >
    <xd:doc scope="stylesheet">
        <xd:desc>
            <xd:p><xd:b>Created on:</xd:b> Jan 25, 2012</xd:p>
            <xd:p><xd:b>Author:</xd:b> King Lung Chiu</xd:p>
            <xd:p></xd:p>
        </xd:desc>
    </xd:doc>
    
    
    <!-- RIF-CS Descripion settings -->
    <xsl:variable name="RIFCS_DESC_MAX_LEN" as="xs:integer" select="4000"/>
    <xsl:variable name="RIFCS_DESC_TYPE_BRIEF" select="'brief'"/>
    <xsl:variable name="RIFCS_DESC_TYPE_FULL" select="'full'"/>
    <xsl:variable name="RIFCS_DESC_TYPE_ACCESS_RIGHTS" select="'accessRights'"/>
    
    
    <!-- ======================================================================
        Returns a sequence of <rifcs:description> elements, each with max length
        of $RIFCS_DESC_MAX_LEN characters. Will split supplied description text
        into multiple elements as required.
        
        To output the result of this function, use <xsl:copy-of> as follows:
        
        <xsl:copy-of select="vxu:createRIFCSDescription('brief', $briefDesc)"/>
        
        paramemters
        - descType
        The type of <rifcs:description>: value goes to rifcs:description/@type.
        To avoid typos, use the predefined RIFCS_DESC_TYPE_* variables.        
        
        - descText
        The text to create <rifcs:description>s from: empty strings will result
        in an empty sequence.
        ====================================================================== -->
    <xsl:function name="vxu:createRIFCSDescription">
        <xsl:param name="descType" as="xs:string"/>
        <xsl:param name="descText" as="xs:string"/>
        <xsl:if test="$descText != ''">
            <rifcs:description type="{$descType}">
                <xsl:value-of select="substring($descText, 1, $RIFCS_DESC_MAX_LEN)"/>
            </rifcs:description>
            <xsl:sequence select="vxu:createRIFCSDescription(
                $descType, substring($descText, $RIFCS_DESC_MAX_LEN + 1))"/>
        </xsl:if>
    </xsl:function>
    
    
    
    <!-- ======================================================================
        Returns true if the suppiled string is in W3C Date Time Format.
        Currently supported formats are:
        
        Year:
            YYYY (eg 1997)
        Year and month:
            YYYY-MM (eg 1997-07)
        Complete date:
            YYYY-MM-DD (eg 1997-07-16)
        Complete date plus hours and minutes:
            YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00)
        
        For details, see:
            - http://www.w3.org/TR/NOTE-datetime
            - http://www.w3schools.com/schema/schema_dtypes_date.asp
        
        paramemters
        - value
        The string to check.        
        ====================================================================== -->
    <xsl:function name="vxu:isW3CDTF" as="xs:boolean">
        <xsl:param name="value" as="xs:string"/>
        <xsl:value-of
            select="($value castable as xs:gYear)
                     or
                    ($value castable as xs:gYearMonth)
                     or
                    ($value castable as xs:date)
                     or
                    ($value castable as xs:dateTime)"/>
    </xsl:function>
    
    
</xsl:stylesheet>